package com.sm.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sm.entity.User;
import com.sm.service.UserService;
import com.sm.util.Constrants;
import com.sm.util.PageQueryUtil;



@Scope("prototype")
@Service("userService")
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class UserServiceImpl extends BaseServiceImpl implements UserService {
	/**
	 * 管理人员登录
	 * 
	 * @param username
	 *            账号
	 * @param password
	 *            登陆密码
	 * @return
	 * @throws Exception
	 */
	public User findUser(String username, String password) throws Exception {
		Object[] objs = { username, password };
		List<User> list = getBaseDao().find(
				"select du from User du where du.username=? and du.password=? and du.isDel=0",
				objs);
		if (list != null && list.size() > 0) {
			
			return (User) list.get(0);
		} else {
			return null;
		}
	}
	
	public User findUserQ(String username) throws Exception {
		Object[] objs = { username};
		List<User> list = getBaseDao().find(
				"select du from User du where du.username=?",
				objs);
		if (list != null && list.size() > 0) {
			
			return (User) list.get(0);
		} else {
			return null;
		}
	}
	
	/**
	 * 分页查询对应管理的系统用户?-不包括超级管理员
	 * 
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> findUserAll(PageQueryUtil page, User user)
			throws Exception {
		String hql; 
		
		hql= "select u from User u where u.isDel=?";
		
		return backPage(hql, page, new Object[] {Constrants.DATA_NOT_DEL });
		
	}
	
	public Map<String, Object> findUserRec(PageQueryUtil page, User user)
			throws Exception {
		String hql; 
		
		hql= "select u from User u where u.isDel=?";
		
		return backPage(hql, page, new Object[] {Constrants.DATA_DEL });
		
	}

	


}
